package org.opens.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.opens.dao.EmpDao;
import org.opens.entity.Emp;
import org.opens.entity.PagerParam;
import org.opens.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Date 2021/5/23 14:04
 * @Created by 99126
 */
@RestController
@RequestMapping(value = "/emp")
public class EmpController {

    @Autowired
    private EmpDao empDao;

    @Autowired
    private EmpService empService;

    @RequestMapping(value = "/hello")
    public String hello() {
        return "hello world";
    }

    @GetMapping(value = "/{empno}")
    public Emp getOne(
            @PathVariable Integer empno
    ) {
        Emp emp = empDao.selectById(empno);
        return emp;
    }

    @GetMapping(value = "/pager")
    public IPage<Emp> pager(PagerParam pagerParam) {
        if (pagerParam.getPageNumber() == 0) {
            pagerParam.setPageNumber(1);
        }
        if (pagerParam.getPageSize() == 0) {
            pagerParam.setPageSize(6);
        }
        return empService.page(pagerParam);
    }

}
